$(document).ready(function() {       
    is_check()  
    var icon = $('<div id="weap-monkwx-icon"><i class="iconfont monk-wx-icon-weixin"></i></div>');    
    var windowWidth = $(window).width();
    var windowHeight = $(window).height();
    var iconWidth = icon.outerWidth();
    var iconHeight = icon.outerHeight();    
    icon.css({
        'position': 'fixed',
        'bottom': ''+GW.is_right_width+'px',
        'right': '4%'
    });
    $('body').on('click', '.monk-wx-btn', function () {        
        var wechat_name=$('.monk-wx-user').find('em').text();            
        $('.monk-wx-box').find('h5').text('复制成功');            
        $('.monk-wx-btn').text('我知道了');            
        if(wechat_name){           
            $('.monk-wx-ts').find('em').text(wechat_name)
        }        
        $('.monk-weixin-open').addClass('monkact');
    });            
    var clipboard = new ClipboardJS('.monk-wx-show,#weap-monkwx-icon', {
        text: function () {
          $('.monk-wx-btn').text('我知道了');            
          $('.monk-wx-box').find('h5').text('复制成功');            
          $('.monk-weixin-open').addClass('monkact');   
          var wechat_name=$('.monk-wx-ts').find('em').text(); 
          return wechat_name;
        },
    });
    var clipboard = new ClipboardJS('.monk-wx-btn', {
        text: function () {                  
          var wechat_name=$('.monk-wx-ts').find('em').text(); 
          return wechat_name;
        },
    });
    $('body').on('click', '.monk-wx-close', function () {
        $('.monk-weixin-open').removeClass('monkact');
        $.ajax({
            type : 'POST',
            url : GW.is_close,
            dataType : 'json',
            success : function(res){
            },error: function(e){}
        });

    });        
    var htm = '<div class="monk-weixin-open"> <div class="monk-wx-box"> <i class="iconfont monk-wx-icon-success"></i> <h5>__ADDWACHAT__</h5> <div class="monk-wx-ow"> <div class="monk-wx-ts"> __WACHATNAME__:<em>__WACHAT__</em> <br> __GUG__ </div> <img src="__CODE__" class="qrcode-ez monkshow"> <a href="weixin://" class="monk-wx-close monk-wx-btn">一键复制</a> </div> <span class="monk-wx-close iconfont monk-wx-icon-close"> </span> </div></div>';
    var tophtm = '<div class="monk-weixin-bar monk-weixin-top"><span class="monk-wx-txt">__WACHATNAME__：<em>__WACHAT__</em></span><span class="monk-wx-add monk-wx-show" data-clipboard-text="__WACHAT__"><i class="iconfont monk-wx-icon-weixin"></i>添加微信</span></div>';
    var topTelhtm = '<div class="monk-weixin-bar monk-weixin-top"><a href="tel:__TEL__" class="monk-wx-tel"><i class="iconfont monk-wx-icon-tel"></i><div>__TEL__</div></a><span class="monk-wx-txt"><em>__TEL__</em></span><span class="monk-wx-add monk-wx-show" data-clipboard-text="__WACHAT__"><i class="iconfont monk-wx-icon-weixin"></i>添加微信</span></div>';
    var dowTelhtm = '<div class="monk-weixin-bar monk-weixin-bot"><a href="tel:__TEL__" class="monk-wx-tel"><i class="iconfont monk-wx-icon-tel"></i><div>__TEL__</div></a><span class="monk-wx-txt">__TEL__</span><span class="monk-wx-add monk-wx-show" data-clipboard-text="__WACHAT__"><i class="iconfont monk-wx-icon-weixin"></i>添加微信</span></div>';
    var dowhtm = '<div class="monk-weixin-bar monk-weixin-bot"><span class="monk-wx-txt">__WACHATNAME__：<em>__WACHAT__</em></span><span class="monk-wx-add monk-wx-show" data-clipboard-text="__WACHAT__"><i class="iconfont monk-wx-icon-weixin"></i>添加微信</span></div>';
    function is_check(){          
        $.ajax({
            type : 'GET',
            url : GW.is_check,
            dataType : 'json',
            success : function(res){                              
                if(res.code == 1){     
                    $('.qrcode-ez').attr('src', res.data.wx_info.code_img);
                    $('.monk-wx-user').find('em').html(res.data.wx_info.wechat_name);
                    $('.monk-wx-tip').html(res.data.ad_intro);
                    $('.monk-weixin-insert').css('display','block');
                    $('.monk-wx-btn ').attr('data-clipboard-text',res.data.wx_info.wechat_name);                
                    if(res.data.is_right==1){
                        $('body').append(icon);
                    }
                    if(res.data.is_top_show==1){
                        $("body").css({ "margin-top": "50px"});                        
                        if(res.data.is_tel_show==1){       
                            var newtopTelhtm=topTelhtm.replace(/__TEL__/g, res.data.tel);                                
                                newtopTelhtm=newtopTelhtm.replace(/__WACHATNAME__/g, res.data.is_value);                             
                                newtopTelhtm=newtopTelhtm.replace(/__WACHAT__/g, res.data.wx_info.wechat_name);                             
                            $('body').append(newtopTelhtm);
                        }else{
                            var newtophtm=tophtm.replace(/__WACHAT__/g, res.data.wx_info.wechat_name);                                
                                newtophtm=newtophtm.replace(/__WACHATNAME__/g, res.data.is_value);                                
                            $('body').append(newtophtm);
                        }                        
                    }
                    if(res.data.is_down_show==1){                             
                        if(res.data.is_tel_show==1){    
                            var newdowTelhtm=dowTelhtm.replace(/__TEL__/g, res.data.tel);                                
                                newdowTelhtm=newdowTelhtm.replace(/__WACHATNAME__/g, res.data.is_value);                                                
                            $('body').append(newdowTelhtm);
                        }else{
                            var newdowhtm=dowhtm.replace(/__WACHAT__/g, res.data.wx_info.wechat_name);                                
                                newdowhtm=newdowhtm.replace(/__WACHATNAME__/g, res.data.is_value);
                            $('body').append(newdowhtm);
                        }                                          
                    }            
                    var newHtml = htm.replace(/__WACHAT__/g, res.data.wx_info.wechat_name);                        
                        newHtml = newHtml.replace(/__GUG__/g, res.data.ad_intro);
                        newHtml = newHtml.replace(/__CODE__/g, res.data.wx_info.code_img);
                        newHtml = newHtml.replace(/__WACHATNAME__/g, res.data.is_value);
                        newHtml = newHtml.replace(/__ADDWACHAT__/g, res.data.is_val);
                    $('body').append(newHtml);
                    if(res.data.is_wind_show==1){                           
                        $('.monk-weixin-open').addClass('monkact');   
                        setInterval(OrderPayPolling, res.data.is_times*1000);
                    }    
                }else{                    
                }
            },
            error: function(e){
            }
        });
    }
});
//是否支付成功
function OrderPayPolling(){        
   $('.monk-weixin-open').addClass('monkact')
}  